<?php
session_start();
include("../db_connect.php");

if(isset($_SESSION['cart']))
{
	if(is_array($_SESSION['cart'])){
		
		$max = count($_SESSION['cart']);
		if($max>0){
			$display = '<table width="200" style="Color:#6d7172;" align="center" border="0">	<tr><td><b>Name</b></td><td><b>Price</b></td><td width="20px"><b>Qty</b></td><td width="10px"><b>X</b></td></tr>';
			for($i=0; $i<$max; $i++){
				$pid = $_SESSION['cart'][$i]['productid'];
				$qty = $_SESSION['cart'][$i]['qty'];
				//echo $pid . "-" . $qty ."<>";
				$display .= displaycart($pid,$qty);
			
			}
			$display .="</tr> </table> <hr>";
			
			$display .= '<div id="crtbutton"><img align="center" src="images/ico_s_basket.png" />&nbsp;<a href="mycart.php" id="cartorder"><b>View Cart</b></a> | <img align="center" src="images/ico_s_remove_item.png" />&nbsp;<a href="#" onclick="deleteallcart()"id="cartdel" style="color:#6d7172;" align="center"><b>Clear Cart</b></a></div>' ;
			echo $display;
		}
		else{
			echo "You dont have any item in your cart";
		}
	}
	else{
		$display = '<table width="200" border="1">	<tr><th><b>Name</b></th><th><b>Price</b></th><th><b>Qty</b></th><th><b>X</b></th></tr>';
		$pid = $_SESSION['cart'][0]['productid'];
		$qty = $_SESSION['cart'][0]['qty'];
		$display .= displaycart($pid,$qty);
		$display .='</tr> </table>';
		
		echo $display;
	}
	
	
}else{
	echo "You dont have any item in your cart";

}

function displaycart($pid,$qty){
		$result=mysql_query("select * from tblswaping where id=$pid") or die("select name from products where id=$pid"."<br/><br/>".mysql_error());
		$display ="";
		$display .= "<tr>";
		while($row = mysql_fetch_array($result)){
			$display .=	'<td><font style="color:#6d7172;" align="center"><label> '. $row['name'] .' </font></label></td>';
			$display .=	'<td><font style="color:#6d7172;" align="center"><img align="top" src="images/p12.gif" height="14" width="14" />'. $row['price'] .' </font></td>  ';
			$display .=	'<td><font style="color:#6d7172;" align="center">'.$qty.' </font></td>';
			$display .=	'<td><a href="#" id="btndelete" onclick="deletecart('.$row['id'].')" ><font align="center" style="color:#6d7172;" align="center">X</font></a></td>';
		}
		
		return $display	;
}



?>